const config = require('./src/config/env')
const VersionCheckPlugin = require('./injection-version-number-plugin')

module.exports = {
  publicPath: '/',
  lintOnSave: true,
  productionSourceMap: false,
  configureWebpack: {
    performance: { hints: false },
    plugins: !config.isDev
      ? [
          new VersionCheckPlugin({
            name: 'srmVersionRefreshKey',
            versionPath: 'dist/version.json',
            htmlPath: 'dist/index.html'
          })
        ]
      : []
  },
  chainWebpack: config => {
    config.externals({
      vue: 'Vue',
      'vue-router': 'VueRouter',
      vuex: 'Vuex',
      axios: 'axios',
      'element-ui': 'ELEMENT'
    })
    const entry = config.entry('app')
    entry.add('babel-polyfill').end()
    entry.add('classlist-polyfill').end()
  },
  css: {
    extract: { ignoreOrder: true },
    loaderOptions: {
      sass: {
        data: `
          @import "~@/styles/variables.scss";
          $ASSETS_CDN: '${config.ASSETS_CDN}';
        `
      }
    }
  },
  devServer: {
    port: 1888,
    proxy: {
      '/api': { target: 'http://172.29.234.19:8080', ws: true, pathRewrite: { '^/api': '' } },
      '/biz-api': { target: 'http://172.29.234.19:8080', ws: true, pathRewrite: { '^/biz-api': '' } }
    }
  }
}
